package com.kit.data.kitopeso.base;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewbinding.ViewBinding;

import com.kit.data.kitopeso.R;


public abstract class BaseDialog<VB extends ViewBinding> extends Dialog {

    protected VB binding;

    protected BtnClickListener onBtnClickListener;

    public BaseDialog(@NonNull Context context) {
        super(context, R.style.CustomAlertDialogTheme);
        init();
    }

    public BaseDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        init();
    }

    protected BaseDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        init();
    }

    void init() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        binding = initViewBinding(LayoutInflater.from(getContext()));
        setContentView(binding.getRoot());
        if(getWindow()!=null) {
            getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            setCanceledOnTouchOutside(false);
            WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
            layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
            layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
            getWindow().setAttributes(layoutParams);
        }


        initView();
    }

    protected abstract VB initViewBinding(LayoutInflater inflater);

    protected abstract void initView();


    public void colse() {
        binding = null;
    }

    public interface BtnClickListener {
        void btnOnClickOk();

        void btnOnClickCancel();

        void btnOnClickColse();
    }

    public void setOnBtnClickListener(BtnClickListener onBtnClickListener) {
        this.onBtnClickListener = onBtnClickListener;
    }
}
